/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.squela.sql

import org.junit.Test

class Queries {
  import QueryBuilder._

  val builder = new SqlSyntaxBuilder(new StandardSqlSyntaxProvider)

  @Test
  def testSelects() {
    println(builder build (select(SerieTable)(SerieTable.fields:_*) where SerieTable.pk.serieName -> "Harmeluno"))
    println(builder build (select(SerieTable)(SerieTable.fields:_*) where SerieTable.chaptersCount > 40))
  }

  class Serie(val name: String, val chaptersCount: Int, val releaseDate: java.util.Date, val hostSite: String,
              val completed: Boolean)
  object SerieTable extends Table("Serie", "S") {
    implicit val self = this
    trait PK extends Table.PrimaryKeyBuilder {
      val serieName = PKField[String]("Name", 50)
    }
    val pk = buildPrimaryKey(new PK{})
    val chaptersCount = Field[Int]("ChapterCount")
    val releaseDate = Field[java.util.Date]("ReleaseDate")
    val hostSite = Field[String]("hostSite", 200)
  }
  class Chapter(val serie: Serie, val name: String, val pagesCount: Int, val date: java.util.Date)

  object ChapterTable extends Table("Chapter", "C") {
    implicit val self = this
    trait PK extends Table.PrimaryKeyBuilder with SerieTable.PK {
      override val onDelete = Table.ConstraintAction.Cascade
      val chapterName = PKField[Int]("Name")
    }
    val pk = buildPrimaryKey(new PK{})
    val pagesCount = Field[Int]("PagesCount")
    val date = Field[java.util.Date]("Date")
  }

}
